package com.poly.flowable.pojo.model;

import com.poly.common.core.tools.utils.Func;
import lombok.Data;
import org.flowable.bpmn.model.FormProperty;
import org.flowable.bpmn.model.UserTask;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class NodeModel implements Serializable {
    private String id;
    private String nodeName;
    private Integer sort;
    /**
     * 节点类型
     * 0开始，1用户任务，2连线, 3网官, 8抄送，9结束
     */
    private Integer type;
    /**
     * 0	未提交
     * 1	审批中
     * 2	已撤销
     * 3	已驳回
     * 6	已通过
     */
    private Integer adopt;

    private List<NodeUserModel> userList = new ArrayList<>();

    private String comment;

    /**
     * 自定义表单
     */
    private String formKey;

    /**
     * 表单属性
     */
    private List<FormProperty> formProperties;

    private Boolean assigneeMulti = false;

    private String assignee;

    public NodeModel(UserTask userTask, String assignee, Integer type, Integer adopt, Integer sort, List<NodeUserModel> userList) {
        this.id = userTask.getId();
        this.nodeName = userTask.getName();
        this.formKey = userTask.getFormKey();
        this.formProperties = userTask.getFormProperties();
        this.assigneeMulti = Func.isNotEmpty(userTask.getLoopCharacteristics());
        this.assignee = assignee;
        this.type = type;
        this.adopt = adopt;
        this.sort = sort;
        if (Func.isNotEmpty(userList)) {
            this.userList = userList;
        }
    }

    public NodeModel(UserTask userTask, String assignee, Integer type, Integer adopt, Integer sort) {
        this.id = userTask.getId();
        this.nodeName = userTask.getName();
        this.formKey = userTask.getFormKey();
        this.formProperties = userTask.getFormProperties();
        this.assigneeMulti = Func.isNotEmpty(userTask.getLoopCharacteristics());
        this.assignee = assignee;
        this.type = type;
        this.adopt = adopt;
        this.sort = sort;
    }

    public NodeModel(String id, String nodeName, Integer type, Integer adopt, Integer sort) {
        this.id = id;
        this.nodeName = nodeName;
        this.type = type;
        this.adopt = adopt;
        this.sort = sort;
    }

    public NodeModel() {
    }
}
